using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Auction_shop_request_product : Member, IRequiresSessionState
{
	protected Literal Reuqest_Class;
	protected Label ClassName;
	protected HiddenField ClassID;
	protected TextBox p_name;
	protected HiddenField H_p_CLASSID;
	protected TextBox ProductDescripe;
	protected FileUpload FileUpload1;
	protected TextBox p_num;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RangeValidator rv1;
	protected TextBox P_uint;
	protected RequiredFieldValidator rfv4;
	protected TextBox p_price;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected RangeValidator RangeValidator3;
	protected TextBox p_validay;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected RangeValidator RangeValidator2;
	protected ScriptManager ScriptManager1;
	protected Shop_UserControls_HowaveProvinceCity HowaveProvinceCity1;
	protected TextBox p_remark;
	protected Label err_tips;
	protected Button prev_Button;
	protected Button submit_btn;
	protected HtmlForm form1;
	protected HtmlGenericControl Html1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "RequestProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.FileUpload1.Attributes.Add("onchange", "document.getElementById('previewImage').innerHTML ='预览<br><img src=\\''+this.value+'\\' width=100 height=100 onload=\\'ResizeImage(this, 100, 100);\\' align=absmiddle id=preview_img>';");
		if (!base.IsPostBack)
		{
			this.BandChangeClassData();
		}
	}
	protected void BandChangeClassData()
	{
		string str = "";
		this.Reuqest_Class.Text = base.Request[str + "h_c_p_className"];
		if (base.Request["h_c_p_classID"] != null && base.Request["h_c_p_classID"] != "")
		{
			this.H_p_CLASSID.Value = base.Request["h_c_p_classID"];
		}
	}
	public int JustCharLenght(string StrChar)
	{
		int num = 0;
		for (int i = 0; i < StrChar.Length; i++)
		{
			if (Convert.ToInt32(Convert.ToChar(StrChar.Substring(i, 1))) > Convert.ToInt32(Convert.ToChar(128)))
			{
				num += 2;
			}
			else
			{
				num++;
			}
		}
		return num;
	}
	protected void submit_btn_click(object sender, EventArgs e)
	{
		string text = this.P_uint.Text;
		string text2 = this.ProductDescripe.Text;
		string value = this.H_p_CLASSID.Value;
		string text3 = this.p_name.Text;
		int productNumber = Convert.ToInt32(this.p_num.Text);
		decimal price = Convert.ToDecimal(this.p_price.Text);
		int validDay = Convert.ToInt32(this.p_validay.Text);
		if (this.JustCharLenght(this.p_name.Text) > 40)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('求购的商品名称长度不能超过40!');</script>");
		}
		else
		{
			DropDownList dropDownList = (DropDownList)this.HowaveProvinceCity1.FindControl("Province");
			DropDownList dropDownList2 = (DropDownList)this.HowaveProvinceCity1.FindControl("City");
			if (dropDownList2.SelectedIndex == 0 || dropDownList.SelectedIndex == 0)
			{
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('请选择地点')</script>");
			}
			else
			{
				string place = dropDownList.SelectedValue + dropDownList2.SelectedValue;
				string text4 = this.p_remark.Text;
				int userID = base.user.UserID;
				if (this.ClassID.Value == null || this.ClassID.Value == "")
				{
					this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('请选择类目!');</script>");
				}
				else
				{
					int productClassID = Convert.ToInt32(this.ClassID.Value);
					int enableRequest = 1;
					string imageUrl = "";
					if (this.FileUpload1.FileName != "")
					{
						imageUrl = this.UploadPhoto();
					}
					Shop_Request shop_Request = new Shop_Request();
					if (shop_Request.AddRequest(userID, text3, productClassID, text2, imageUrl, place, price, validDay, text4, productNumber, 1, enableRequest, text))
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert(\"提交成功\");window.location.href='../Member/Shop_Request.aspx'</script>");
					}
					else
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert(\"提交失败,请稍候再试\");</script>");
					}
				}
			}
		}
	}
	protected string UploadPhoto()
	{
		Watermark watermark = new Watermark();
		string str = DateTime.Now.ToString("yyyyMM");
		string uploadFilePath = base.Server.MapPath("UploadFile\\ShopRequest\\" + str + "\\");
		string str2 = watermark.UploadPic(this.FileUpload1.PostedFile, uploadFilePath, "", true, true, 220, 220);
		return "/UploadFile/ShopRequest/" + str + "/" + str2;
	}
}
